//https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/?envType=study-plan&id=lcof&plan=lcof&plan_progress=jp9wi1h
class Solution {
public:
    ListNode* getKthFromEnd(ListNode* head, int k) {
        ListNode* cur = head;
        ListNode* prev = head;

        while (k-- && cur)
        {
            cur = cur->next;
        }
        if (cur == nullptr)
        {
            return head;
        }

        while (cur)
        {
            cur = cur->next;
            prev = prev->next;
        }

        return prev;
    }
};